<?php
// not installed?
if ( !file_exists(dirname(__FILE__) .'/cse-config.php') ) {
	header('Location: admin/install.php');
	exit;
}

// looking for reports?
if ( !isset($_GET['action']) && !isset($_POST['action']) ) {
	header('Location: reports/index.php');
	exit;
}

require_once dirname(__FILE__) .'/cse-init.php';

$session = Cinnamon::registry('session');
$params = Cinnamon::registry('params');

// update filters settings
if ( isset($params->action) && $params->action == 'saveFilters' ) {
	foreach ( $params as $name=>$value) {
		if ( preg_match('/^filters_/', $name) ) {
			$name = str_replace('_', '.', $name);		// create session filter name
			$session->set($name, $value);				// change filter value
		}
	}
	// redirect if url is specified
	if ( isset($params->url) ) {
		header("Location: ". urldecode($params->url));
	} else {
		header("Location: index.php");
	}
} else {
	//require_once dirname(__FILE__) .'/reports/index.php';
	header('Location: reports/index.php');
}
?>